// const API = "../";//正式打包用
const API = 'zj/'
const webUrl = 'http://admin.izujie.com/#'
// const webUrl='http://47.93.126.158:8000/#'
//const webUrl = 'http://localhost:9080/#'
// const webUrl = 'http://192.168.0.230:8000/#'
const HEADER_FORM_URL = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
}
const HEADER_JSON = {
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  }
}
const YES_NO = [{
  value: true,
  label: '是'
}, {
  value: false,
  label: '否'
}]

const NEW_OLD = [{
  value: true,
  label: '新'
}, {
  value: false,
  label: '旧'
}]

function commerror (err) {
  console.log('global_err', err)
  // if (result.responseText.indexOf("注册") > -1) {
  // 	window.location.href = "newindex/index.html?newReg=g";
  // } else if (result.responseText == "") {
  // 	alert("访问信息不正确，请稍后再试或重新登录！");
  // } else {
  // 	alert(result.responseText);
  // }
}

function isvalid (row, column) {
  let value = row[column.property]
  if (value == null) return ''
  if (value == 1 || value == true) {
    return '启用'
  } else {
    return '禁用'
  }
}

function isvalidAuditing (row, column) {
  let value = row[column.property]
  if (value == null) return ''
  if (value == 1 || value == true) {
    return '已认证'
  } else {
    return '未认证'
  }
}

function formatterYesNo (row, column) {
  let value = row[column.property]
  if (value == null) return ''
  if (value == 1 || value == true) {
    return '是'
  } else {
    return '否'
  }
}

function formatterNewOld (row, column) {
    let value = row[column.property]
    if (value == null) return ''
    if (value == 1 || value == true) {
        return '新'
    } else {
        return '旧'
    }
}

function formatterDate (row, column, cellValue) {
  let value = cellValue
  if (value != '' && value != undefined && value) {
    var date = new Date(value)
    return date.getFullYear() + '-' + pad(date.getMonth() + 1, 2) + '-'
      + pad(date.getDate(), 2)
  }
  else {
    return ''
  }
  return value
}

function formatDatePicker (value) {
  if (value != '' && value != undefined && value && value != null) {
    let date = new Date(value)
    return date.getFullYear() + '-' + pad((date.getMonth() + 1), 2) + '-'
      + pad(date.getDate(), 2)
  }
  else {
    return ''
  }
  return value
}

function formatMonthPicker (value) {
  if (value != '' && value != undefined && value) {
    let date = new Date(value)
    return date.getFullYear() + '-' + pad((date.getMonth() + 1), 2)
  }
  else {
    return ''
  }
  return value
}

function formatDatetimePicker (value) {
  if (value != '' && value != undefined && value) {
    let date = new Date(value)
    return date.getFullYear() + '-' + pad((date.getMonth() + 1), 2) + '-'
      + pad(date.getDate(), 2) + ' ' + pad(date.getHours(), 2) + ':' + pad(date.getMinutes(), 2)
      + ':' + pad(date.getSeconds(), 2)
  }
  else {
    return ''
  }
  return value
}

function pad (num, n) {
  let len = num.toString().length
  while (len < n) {
    num = '0' + num
    len++
  }
  return num
}

function formatterYearMonth (row, column, cellValue) {
  let value = cellValue
  if (value != '' && value != undefined && value) {
    var date = new Date(value)
    return date.getFullYear() + '-' + pad(date.getMonth() + 1, 2)
  }
  else {
    return ''
  }
  return value
}

function formatYearMonthPicker (value) {
  if (value != '' && value != undefined && value) {
    let date = new Date(value)
    return date.getFullYear() + '-' + pad((date.getMonth() + 1), 2)
  }
  else {
    return ''
  }
  return value
}

function getCaption(obj) {
    let index = obj.lastIndexOf("\.");
    obj = obj.substring(index + 1, obj.length);
    return obj;
}

function formatterPhone (row, column) {
    let value = row[column.property]
    if (value == null || value === '') {
      return ''
    }
    return value.substring(0,3) + '****' + value.substring(7,value.length)
}

export default {
  webUrl,
  API,
  HEADER_FORM_URL,
  HEADER_JSON,
  YES_NO,
  NEW_OLD,
  commerror,
  pad,
  isvalid,
  isvalidAuditing,
  formatterYesNo,
  formatterDate,
  formatDatePicker,
  formatMonthPicker,
  formatDatetimePicker,
  formatterYearMonth,
  formatYearMonthPicker,
  formatterNewOld,
  getCaption,
  formatterPhone
}
